//
//  BVPlaygroundSearchView.m
//  AFNetworking
//
//  Created by xiute on 2019/10/22.
//

#import "BVPlaygroundSearchView.h"
#import "Masonry.h"
#import "BVPlaygroundSearchTableViewCell.h"

@interface BVPlaygroundSearchView ()

@property (nonatomic, strong) NSMutableArray<BVMetaArena *> *dataSource;

@end

@implementation BVPlaygroundSearchView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor clearColor];
    
}

- (void)configDataSource:(NSArray *)dataSource {
    self.dataSource = [NSMutableArray arrayWithArray:dataSource];
}

#pragma mark - tableview delegate and datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BVPlaygroundSearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BVPlaygroundSearchTableViewCell" forIndexPath:indexPath];
    [cell configWithModel:self.dataSource[indexPath.row]];
    __weak typeof(self)weakSelf = self;
    cell.clickBlock = ^{
        if (weakSelf.selectBlock) {
            weakSelf.selectBlock(weakSelf.dataSource[indexPath.row]);
        }
    };
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.selectBlock) {
        self.selectBlock(self.dataSource[indexPath.row]);
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}


- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, nil, 30, 0);
    CGPathAddLineToPoint(path, nil, 22, 7);
    CGPathAddLineToPoint(path, nil, 38, 7);
    CGPathAddLineToPoint(path, nil, 30, 0);
    CGContextAddPath(context, path);
    
    CGContextSetFillColorWithColor(context, [UIColor colorWithWhite:1 alpha:1].CGColor);
    CGContextSetLineWidth(context, 1);
    CGContextDrawPath(context, kCGPathFill);
    CGPathRelease(path);
    
    
}
@end
